package days38.title5;

class Solution {
    public String longestPalindrome(String s) {
        int maxCount = 0;
        StringBuilder stringBuffer = new StringBuilder(s);
        StringBuilder stringBuffer3 = new StringBuilder(s);
        if (s.contentEquals(stringBuffer3.reverse()))
            return s;
        String result = s.substring(0,1);
        for (int i = 0; i < s.length(); i++) {
            for (int j = i; j < s.length(); j++) {
                StringBuilder stringBuffer1 = new StringBuilder(stringBuffer.substring(i,j+1));
                StringBuilder stringBuffer2 = new StringBuilder(stringBuffer.substring(i,j+1));
                if (stringBuffer2.compareTo(stringBuffer1.reverse()) == 0){
                    if ((j-i)>maxCount){
                        maxCount = j-i;
                        result = stringBuffer2.toString();
                    }
                }
            }
        }
        return result;
    }
}